#include <string>
#include "atomic.h"
#include "message.h"
#include "mainsimu.h"
#include "strutil.h"
#include "../HeadFile/PCS_mixing_2_model.h"


/**** the Constructor ****/
PCS_mixing_2_model::PCS_mixing_2_model( const string &name)
: Atomic( name )
, PCS_mixing_2_stream_VR_1( this->addInputPort( "PCS_mixing_2_stream_VR_1") )
, PCS_mixing_2_stream_VR_2( this->addInputPort( "PCS_mixing_2_stream_VR_2") )
, PCS_mixing_2_stream_VR_3( this->addOutputPort( "PCS_mixing_2_stream_VR_3") )
{

}


/*** the initFunction ***/
Model &PCS_mixing_2_model::initFunction()
{

		
	PCS_mixing_2_stream_VR_3_flowrate = 0;
	count = 0;
	count = 0;
	delay = "00:00:00:00";
	passivate();
	return *this;
		
		
}

/*** the externalFunction ***/
Model &PCS_mixing_2_model::externalFunction( const ExternalMessage &msg )
{

			
	if( msg.port() == PCS_mixing_2_stream_VR_1 ){
		PCS_mixing_2_stream_VR_1_flowrate = msg.value();
		PCS_mixing_2_stream_VR_3_flowrate += PCS_mixing_2_stream_VR_1_flowrate;
		count++;
		holdIn( active, delay);
		return *this;
	}
	if( msg.port() == PCS_mixing_2_stream_VR_2 ){
		PCS_mixing_2_stream_VR_2_flowrate = msg.value();
		PCS_mixing_2_stream_VR_3_flowrate += PCS_mixing_2_stream_VR_2_flowrate;
		count++;
		holdIn( active, delay);
		return *this;
	}
		
		
}

/*** the internalFunction ***/
Model &PCS_mixing_2_model::internalFunction( const InternalMessage &msg )
{

			
	passivate();
	return *this;
		
		
}

/*** the outputFunction ***/
Model &PCS_mixing_2_model::outputFunction( const InternalMessage &msg )
{

			
	if(count == 2)
	{
		sendOutput( msg.time(), PCS_mixing_2_stream_VR_3, PCS_mixing_2_stream_VR_3_flowrate);
		PCS_mixing_2_stream_VR_3_flowrate = 0;
		count = 0;
	}
	return *this;
		
		
}

